package tp.pr3;

import java.io.*;

import tp.pr3.Game;
import tp.pr3.maploader.MapLoaderFromTxtFile;

public class Main {
    

	private static Map loadFile(String nombre) throws IOException{
		Map mapa = null;
		FileInputStream file = null;
		try {
		MapLoaderFromTxtFile mlftf = new MapLoaderFromTxtFile();
		 file =new FileInputStream(nombre);
		 mapa = mlftf.loadMap(file);
		 file.close();
		}catch (FileNotFoundException e) {
			throw e;
		}
		catch (IOException e) {
			file.close();
			throw e;
		}
		return mapa;
		
	}
	
	
    public static void main(java.lang.String[] args) {
    	String fileName = null;
    	if(args.length >1)
			System.out.println("Only first arg will be used.");
    	try{
    		
    	Map mapa = loadFile(fileName);
    	if (mapa==null) throw new NullPointerException();
			Game game = new Game(mapa);
			game.runGame();
			
    	}catch (Exception e) {
    		Runtime.getRuntime().exit(1);
		}
    	}
    	}
    